package DataStructure.iterator;

import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

public class IteratorSetTest {
    public static void main(String[] args) {
      Set<String> set = new HashSet<>();
      set.add("a");
      set.add("b");
      set.add("c");

      //方式一：在迭代器中通过while获取元素
      //获取迭代器对象
      Iterator<String> it = set.iterator();
      while(it.hasNext()){
          System.out.println(it.next());
      }

      //方式二：在迭代器中通过for获取元素
        for(Iterator<String> it2 = set.iterator();it2.hasNext();){
            System.out.println(it2.next());
        }
    }
}
